<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Safe #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  System.Environment</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Miscellaneous information about the system environment.</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Environment</span><span>
</span><span id="line-19"></span><span>    </span><span class="hs-special">(</span><span>
</span><span id="line-20"></span><span>      </span><span class="annot"><a href="System.Environment.html#getArgs"><span class="hs-identifier">getArgs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>      </span><span class="annot"><a href="System.Environment.html#getProgName"><span class="hs-identifier">getProgName</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>      </span><span class="annot"><a href="System.Environment.ExecutablePath.html#getExecutablePath"><span class="hs-identifier">getExecutablePath</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>      </span><span class="annot"><a href="System.Environment.html#getEnv"><span class="hs-identifier">getEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-24"></span><span>      </span><span class="annot"><a href="System.Environment.html#lookupEnv"><span class="hs-identifier">lookupEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>      </span><span class="annot"><a href="System.Environment.html#setEnv"><span class="hs-identifier">setEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>      </span><span class="annot"><a href="System.Environment.html#unsetEnv"><span class="hs-identifier">unsetEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>      </span><span class="annot"><a href="System.Environment.html#withArgs"><span class="hs-identifier">withArgs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>      </span><span class="annot"><a href="System.Environment.html#withProgName"><span class="hs-identifier">withProgName</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>      </span><span class="annot"><a href="System.Environment.html#getEnvironment"><span class="hs-identifier">getEnvironment</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.html"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.html"><span class="hs-identifier">Foreign.C</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.IO.Error.html"><span class="hs-identifier">System.IO.Error</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="System.IO.Error.html#mkIOError"><span class="hs-identifier">mkIOError</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Control.Exception.Base.html"><span class="hs-identifier">Control.Exception.Base</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Exception.Base.html#bracket_"><span class="hs-identifier">bracket_</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#throwIO"><span class="hs-identifier">throwIO</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Control.Exception.Base.html"><span class="hs-identifier">Control.Exception.Base</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Exception.Base.html#bracket"><span class="hs-identifier">bracket</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-comment">-- import GHC.IO</span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.Foreign.html"><span class="hs-identifier">GHC.Foreign</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">GHC</span></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Control.Monad.html"><span class="hs-identifier">Control.Monad</span></a></span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html"><span class="hs-identifier">GHC.IO.Encoding</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Encoding.html#argvEncoding"><span class="hs-identifier">argvEncoding</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Windows.html"><span class="hs-identifier">GHC.Windows</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Encoding</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">getFileSystemEncoding</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">argvEncoding</span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Posix.Internals</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">withFilePath</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Environment.ExecutablePath.html"><span class="hs-identifier">System.Environment.ExecutablePath</span></a></span><span class="hs-cpp">

#if defined(mingw32_HOST_OS)
</span><span class="hs-cpp"># if defined(i386_HOST_ARCH)
</span><span class="hs-cpp">#  define WINDOWS_CCONV stdcall
</span><span class="hs-cpp"># elif defined(x86_64_HOST_ARCH)
</span><span class="hs-cpp">#  define WINDOWS_CCONV ccall
</span><span class="hs-cpp"># else
</span><span class="hs-cpp">#  error Unknown mingw32 arch
</span><span class="hs-cpp"># endif
</span><span class="hs-cpp">#endif
</span><span class="hs-cpp">
#include &quot;HsBaseConfig.h&quot;
</span><span>
</span><span id="line-65"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-66"></span><span class="hs-comment">-- getArgs, getProgName, getEnv</span><span>
</span><span id="line-67"></span><span>
</span><span id="line-68"></span><span class="hs-comment">-- | Computation 'getArgs' returns a list of the program's command</span><span>
</span><span id="line-69"></span><span class="hs-comment">-- line arguments (not including the program name).</span><span>
</span><span id="line-70"></span><span class="annot"><a href="System.Environment.html#getArgs"><span class="hs-identifier hs-type">getArgs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-71"></span><span id="getArgs"><span class="annot"><span class="annottext">getArgs :: IO [String]
</span><a href="System.Environment.html#getArgs"><span class="hs-identifier hs-var hs-var">getArgs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-72"></span><span>  </span><span class="annot"><span class="annottext">(Ptr CInt -&gt; IO [String]) -&gt; IO [String]
forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var">alloca</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CInt -&gt; IO [String]) -&gt; IO [String])
-&gt; (Ptr CInt -&gt; IO [String]) -&gt; IO [String]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679564239"><span class="annot"><span class="annottext">Ptr CInt
</span><a href="#local-6989586621679564239"><span class="hs-identifier hs-var">p_argc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-73"></span><span>  </span><span class="annot"><span class="annottext">(Ptr (Ptr (Ptr CChar)) -&gt; IO [String]) -&gt; IO [String]
forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var">alloca</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr (Ptr (Ptr CChar)) -&gt; IO [String]) -&gt; IO [String])
-&gt; (Ptr (Ptr (Ptr CChar)) -&gt; IO [String]) -&gt; IO [String]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679564238"><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar))
</span><a href="#local-6989586621679564238"><span class="hs-identifier hs-var">p_argv</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-74"></span><span>   </span><span class="annot"><span class="annottext">Ptr CInt -&gt; Ptr (Ptr (Ptr CChar)) -&gt; IO ()
</span><a href="System.Environment.html#getProgArgv"><span class="hs-identifier hs-var">getProgArgv</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CInt
</span><a href="#local-6989586621679564239"><span class="hs-identifier hs-var">p_argc</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar))
</span><a href="#local-6989586621679564238"><span class="hs-identifier hs-var">p_argv</span></a></span><span>
</span><span id="line-75"></span><span>   </span><span id="local-6989586621679564236"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679564236"><span class="hs-identifier hs-var">p</span></a></span></span><span>    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CInt -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">(CInt -&gt; Int) -&gt; IO CInt -&gt; IO Int
forall (m :: * -&gt; *) a1 r. Monad m =&gt; (a1 -&gt; r) -&gt; m a1 -&gt; m r
</span><a href="GHC.Base.html#liftM"><span class="hs-operator hs-var">`liftM`</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CInt -&gt; IO CInt
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CInt
</span><a href="#local-6989586621679564239"><span class="hs-identifier hs-var">p_argc</span></a></span><span>
</span><span id="line-76"></span><span>   </span><span id="local-6989586621679564233"><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564233"><span class="hs-identifier hs-var">argv</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar)) -&gt; IO (Ptr (Ptr CChar))
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar))
</span><a href="#local-6989586621679564238"><span class="hs-identifier hs-var">p_argv</span></a></span><span>
</span><span id="line-77"></span><span>   </span><span id="local-6989586621679564232"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679564232"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#argvEncoding"><span class="hs-identifier hs-var">argvEncoding</span></a></span><span>
</span><span id="line-78"></span><span>   </span><span class="annot"><span class="annottext">Int -&gt; Ptr (Ptr CChar) -&gt; IO [Ptr CChar]
forall a. Storable a =&gt; Int -&gt; Ptr a -&gt; IO [a]
</span><a href="Foreign.Marshal.Array.html#peekArray"><span class="hs-identifier hs-var">peekArray</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679564236"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr (Ptr CChar) -&gt; Int -&gt; Ptr (Ptr CChar)
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; Ptr a
</span><a href="Foreign.Marshal.Array.html#advancePtr"><span class="hs-identifier hs-var">advancePtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564233"><span class="hs-identifier hs-var">argv</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO [Ptr CChar] -&gt; ([Ptr CChar] -&gt; IO [String]) -&gt; IO [String]
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr CChar -&gt; IO String) -&gt; [Ptr CChar] -&gt; IO [String]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextEncoding -&gt; Ptr CChar -&gt; IO String
</span><a href="GHC.Foreign.html#peekCString"><span class="hs-identifier hs-var">GHC.peekCString</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679564232"><span class="hs-identifier hs-var">enc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getProgArgv&quot;</span></span><span>
</span><span id="line-82"></span><span>  </span><span id="getProgArgv"><span class="annot"><a href="System.Environment.html#getProgArgv"><span class="hs-identifier hs-var">getProgArgv</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-83"></span><span>
</span><span id="line-84"></span><span class="hs-comment">{-|
Computation 'getProgName' returns the name of the program as it was
invoked.

However, this is hard-to-impossible to implement on some non-Unix
OSes, so instead, for maximum portability, we just return the leafname
of the program as invoked. Even then there are some differences
between platforms: on Windows, for example, a program invoked as foo
is probably really @FOO.EXE@, and that is what 'getProgName' will return.
-}</span><span>
</span><span id="line-94"></span><span class="annot"><a href="System.Environment.html#getProgName"><span class="hs-identifier hs-type">getProgName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-95"></span><span class="hs-comment">-- Ignore the arguments to hs_init on Windows for the sake of Unicode compat</span><span>
</span><span id="line-96"></span><span id="getProgName"><span class="annot"><span class="annottext">getProgName :: IO String
</span><a href="System.Environment.html#getProgName"><span class="hs-identifier hs-var hs-var">getProgName</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-97"></span><span>  </span><span class="annot"><span class="annottext">(Ptr CInt -&gt; IO String) -&gt; IO String
forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var">alloca</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CInt -&gt; IO String) -&gt; IO String)
-&gt; (Ptr CInt -&gt; IO String) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679564226"><span class="annot"><span class="annottext">Ptr CInt
</span><a href="#local-6989586621679564226"><span class="hs-identifier hs-var">p_argc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-98"></span><span>  </span><span class="annot"><span class="annottext">(Ptr (Ptr (Ptr CChar)) -&gt; IO String) -&gt; IO String
forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var">alloca</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr (Ptr (Ptr CChar)) -&gt; IO String) -&gt; IO String)
-&gt; (Ptr (Ptr (Ptr CChar)) -&gt; IO String) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679564225"><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar))
</span><a href="#local-6989586621679564225"><span class="hs-identifier hs-var">p_argv</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-99"></span><span>     </span><span class="annot"><span class="annottext">Ptr CInt -&gt; Ptr (Ptr (Ptr CChar)) -&gt; IO ()
</span><a href="System.Environment.html#getProgArgv"><span class="hs-identifier hs-var">getProgArgv</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CInt
</span><a href="#local-6989586621679564226"><span class="hs-identifier hs-var">p_argc</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar))
</span><a href="#local-6989586621679564225"><span class="hs-identifier hs-var">p_argv</span></a></span><span>
</span><span id="line-100"></span><span>     </span><span id="local-6989586621679564224"><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564224"><span class="hs-identifier hs-var">argv</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar)) -&gt; IO (Ptr (Ptr CChar))
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr (Ptr CChar))
</span><a href="#local-6989586621679564225"><span class="hs-identifier hs-var">p_argv</span></a></span><span>
</span><span id="line-101"></span><span>     </span><span class="annot"><span class="annottext">Ptr (Ptr CChar) -&gt; IO String
</span><a href="System.Environment.html#unpackProgName"><span class="hs-identifier hs-var">unpackProgName</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564224"><span class="hs-identifier hs-var">argv</span></a></span><span>
</span><span id="line-102"></span><span>
</span><span id="line-103"></span><span class="annot"><a href="System.Environment.html#unpackProgName"><span class="hs-identifier hs-type">unpackProgName</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CChar"><span class="hs-identifier hs-type">CChar</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>   </span><span class="hs-comment">-- argv[0]</span><span>
</span><span id="line-104"></span><span id="unpackProgName"><span class="annot"><span class="annottext">unpackProgName :: Ptr (Ptr CChar) -&gt; IO String
</span><a href="System.Environment.html#unpackProgName"><span class="hs-identifier hs-var hs-var">unpackProgName</span></a></span></span><span> </span><span id="local-6989586621679564222"><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564222"><span class="hs-identifier hs-var">argv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-105"></span><span>  </span><span id="local-6989586621679564221"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679564221"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#argvEncoding"><span class="hs-identifier hs-var">argvEncoding</span></a></span><span>
</span><span id="line-106"></span><span>  </span><span id="local-6989586621679564220"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564220"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr CChar) -&gt; Int -&gt; IO (Ptr CChar)
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564222"><span class="hs-identifier hs-var">argv</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">IO (Ptr CChar) -&gt; (Ptr CChar -&gt; IO String) -&gt; IO String
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; Ptr CChar -&gt; IO String
</span><a href="GHC.Foreign.html#peekCString"><span class="hs-identifier hs-var">GHC.peekCString</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679564221"><span class="hs-identifier hs-var">enc</span></a></span><span>
</span><span id="line-107"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; String
</span><a href="System.Environment.html#basename"><span class="hs-identifier hs-var">basename</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564220"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-108"></span><span>
</span><span id="line-109"></span><span class="annot"><a href="System.Environment.html#basename"><span class="hs-identifier hs-type">basename</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-110"></span><span id="basename"><span class="annot"><span class="annottext">basename :: String -&gt; String
</span><a href="System.Environment.html#basename"><span class="hs-identifier hs-var hs-var">basename</span></a></span></span><span> </span><span id="local-6989586621679564216"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564216"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
</span><a href="#local-6989586621679564215"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564216"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564216"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-111"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-112"></span><span>  </span><span id="local-6989586621679564215"><span class="annot"><span class="annottext">go :: String -&gt; String -&gt; String
</span><a href="#local-6989586621679564215"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679564214"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564214"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564214"><span class="hs-identifier hs-var">acc</span></a></span><span>
</span><span id="line-113"></span><span>  </span><span class="annot"><a href="#local-6989586621679564215"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621679564213"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564213"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679564212"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679564212"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679564211"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564211"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-114"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Char -&gt; Bool
</span><a href="#local-6989586621679564210"><span class="hs-identifier hs-var">isPathSeparator</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679564212"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
</span><a href="#local-6989586621679564215"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564211"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564211"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-115"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
</span><a href="#local-6989586621679564215"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564213"><span class="hs-identifier hs-var">acc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564211"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span>  </span><span class="annot"><a href="#local-6989586621679564210"><span class="hs-identifier hs-type">isPathSeparator</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-118"></span><span>  </span><span id="local-6989586621679564210"><span class="annot"><span class="annottext">isPathSeparator :: Char -&gt; Bool
</span><a href="#local-6989586621679564210"><span class="hs-identifier hs-var hs-var">isPathSeparator</span></a></span></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'/'</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span>  </span><span class="annot"><a href="#local-6989586621679564210"><span class="hs-identifier hs-var">isPathSeparator</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\\'</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-cpp">
#endif
</span><span>  </span><span class="annot"><a href="#local-6989586621679564210"><span class="hs-identifier hs-var">isPathSeparator</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-identifier">_</span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-123"></span><span>
</span><span id="line-124"></span><span>
</span><span id="line-125"></span><span class="hs-comment">-- | Computation 'getEnv' @var@ returns the value</span><span>
</span><span id="line-126"></span><span class="hs-comment">-- of the environment variable @var@. For the inverse, the</span><span>
</span><span id="line-127"></span><span class="hs-comment">-- `System.Environment.setEnv` function can be used.</span><span>
</span><span id="line-128"></span><span class="hs-comment">--</span><span>
</span><span id="line-129"></span><span class="hs-comment">-- This computation may fail with:</span><span>
</span><span id="line-130"></span><span class="hs-comment">--</span><span>
</span><span id="line-131"></span><span class="hs-comment">--  * 'System.IO.Error.isDoesNotExistError' if the environment variable</span><span>
</span><span id="line-132"></span><span class="hs-comment">--    does not exist.</span><span>
</span><span id="line-133"></span><span>
</span><span id="line-134"></span><span class="annot"><a href="System.Environment.html#getEnv"><span class="hs-identifier hs-type">getEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-135"></span><span id="getEnv"><span class="annot"><span class="annottext">getEnv :: String -&gt; IO String
</span><a href="System.Environment.html#getEnv"><span class="hs-identifier hs-var hs-var">getEnv</span></a></span></span><span> </span><span id="local-6989586621679564209"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564209"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (Maybe String)
</span><a href="System.Environment.html#lookupEnv"><span class="hs-identifier hs-var">lookupEnv</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564209"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">IO (Maybe String) -&gt; (Maybe String -&gt; IO String) -&gt; IO String
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">IO String -&gt; (String -&gt; IO String) -&gt; Maybe String -&gt; IO String
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="annot"><span class="annottext">IO String
forall {b}. IO b
</span><a href="#local-6989586621679564207"><span class="hs-identifier hs-var">handleError</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span>
</span><span id="line-136"></span><span>  </span><span class="hs-keyword">where</span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span>    </span><span id="local-6989586621679564207"><span class="annot"><span class="annottext">handleError :: IO b
</span><a href="#local-6989586621679564207"><span class="hs-identifier hs-var hs-var">handleError</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-139"></span><span>        </span><span id="local-6989586621679564204"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564204"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO DWORD
</span><a href="System.Environment.html#c_GetLastError"><span class="hs-identifier hs-var">c_GetLastError</span></a></span><span>
</span><span id="line-140"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564204"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; DWORD -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="System.Environment.html#eRROR_ENVVAR_NOT_FOUND"><span class="hs-identifier hs-var">eRROR_ENVVAR_NOT_FOUND</span></a></span><span>
</span><span id="line-141"></span><span>            </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO b
forall a. String -&gt; IO a
</span><a href="System.Environment.html#ioe_missingEnvVar"><span class="hs-identifier hs-var">ioe_missingEnvVar</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564209"><span class="hs-identifier hs-var">name</span></a></span><span>
</span><span id="line-142"></span><span>            </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO b
forall a. String -&gt; IO a
</span><a href="GHC.Windows.html#throwGetLastError"><span class="hs-identifier hs-var">throwGetLastError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;getEnv&quot;</span></span><span>
</span><span id="line-143"></span><span>
</span><span id="line-144"></span><span class="annot"><a href="System.Environment.html#eRROR_ENVVAR_NOT_FOUND"><span class="hs-identifier hs-type">eRROR_ENVVAR_NOT_FOUND</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span>
</span><span id="line-145"></span><span id="eRROR_ENVVAR_NOT_FOUND"><span class="annot"><span class="annottext">eRROR_ENVVAR_NOT_FOUND :: DWORD
</span><a href="System.Environment.html#eRROR_ENVVAR_NOT_FOUND"><span class="hs-identifier hs-var hs-var">eRROR_ENVVAR_NOT_FOUND</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">203</span></span><span>
</span><span id="line-146"></span><span>
</span><span id="line-147"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h GetLastError&quot;</span><span>
</span><span id="line-148"></span><span>  </span><span id="c_GetLastError"><span class="annot"><a href="System.Environment.html#c_GetLastError"><span class="hs-identifier hs-var">c_GetLastError</span></a></span></span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span class="hs-cpp">

#else
</span><span>    </span><span class="hs-identifier">handleError</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ioe_missingEnvVar</span><span> </span><span class="hs-identifier">name</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-154"></span><span class="hs-comment">-- | Return the value of the environment variable @var@, or @Nothing@ if</span><span>
</span><span id="line-155"></span><span class="hs-comment">-- there is no such value.</span><span>
</span><span id="line-156"></span><span class="hs-comment">--</span><span>
</span><span id="line-157"></span><span class="hs-comment">-- For POSIX users, this is equivalent to 'System.Posix.Env.getEnv'.</span><span>
</span><span id="line-158"></span><span class="hs-comment">--</span><span>
</span><span id="line-159"></span><span class="hs-comment">-- @since 4.6.0.0</span><span>
</span><span id="line-160"></span><span class="annot"><a href="System.Environment.html#lookupEnv"><span class="hs-identifier hs-type">lookupEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span id="lookupEnv"><span class="annot"><span class="annottext">lookupEnv :: String -&gt; IO (Maybe String)
</span><a href="System.Environment.html#lookupEnv"><span class="hs-identifier hs-var hs-var">lookupEnv</span></a></span></span><span> </span><span id="local-6989586621679564199"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564199"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; (Ptr CWchar -&gt; IO (Maybe String)) -&gt; IO (Maybe String)
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564199"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (Maybe String)) -&gt; IO (Maybe String))
-&gt; (Ptr CWchar -&gt; IO (Maybe String)) -&gt; IO (Maybe String)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679564197"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564197"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; DWORD -&gt; IO (Maybe String)
</span><a href="#local-6989586621679564196"><span class="hs-identifier hs-var">try_size</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564197"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">256</span></span><span>
</span><span id="line-163"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-164"></span><span>    </span><span id="local-6989586621679564196"><span class="annot"><span class="annottext">try_size :: Ptr CWchar -&gt; DWORD -&gt; IO (Maybe String)
</span><a href="#local-6989586621679564196"><span class="hs-identifier hs-var hs-var">try_size</span></a></span></span><span> </span><span id="local-6989586621679564182"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564182"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span id="local-6989586621679564181"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564181"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (Ptr CWchar -&gt; IO (Maybe String)) -&gt; IO (Maybe String)
forall a b. Storable a =&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Array.html#allocaArray"><span class="hs-identifier hs-var">allocaArray</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DWORD -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564181"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (Maybe String)) -&gt; IO (Maybe String))
-&gt; (Ptr CWchar -&gt; IO (Maybe String)) -&gt; IO (Maybe String)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679564179"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564179"><span class="hs-identifier hs-var">p_value</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-165"></span><span>      </span><span id="local-6989586621679564178"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564178"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; Ptr CWchar -&gt; DWORD -&gt; IO DWORD
</span><a href="System.Environment.html#c_GetEnvironmentVariable"><span class="hs-identifier hs-var">c_GetEnvironmentVariable</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564182"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564179"><span class="hs-identifier hs-var">p_value</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564181"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-166"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564178"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-167"></span><span>        </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe String -&gt; IO (Maybe String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-168"></span><span>        </span><span class="annot"><span class="annottext">DWORD
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564178"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; DWORD -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564181"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; DWORD -&gt; IO (Maybe String)
</span><a href="#local-6989586621679564196"><span class="hs-identifier hs-var">try_size</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564182"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564178"><span class="hs-identifier hs-var">res</span></a></span><span> </span><span class="hs-comment">-- Rare: size increased between calls to GetEnvironmentVariable</span><span>
</span><span id="line-169"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO String
</span><a href="Foreign.C.String.html#peekCWString"><span class="hs-identifier hs-var">peekCWString</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564179"><span class="hs-identifier hs-var">p_value</span></a></span><span> </span><span class="annot"><span class="annottext">IO String -&gt; (String -&gt; IO (Maybe String)) -&gt; IO (Maybe String)
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String -&gt; IO (Maybe String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe String -&gt; IO (Maybe String))
-&gt; (String -&gt; Maybe String) -&gt; String -&gt; IO (Maybe String)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Maybe String
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span>
</span><span id="line-170"></span><span>
</span><span id="line-171"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h GetEnvironmentVariableW&quot;</span><span>
</span><span id="line-172"></span><span>  </span><span id="c_GetEnvironmentVariable"><span class="annot"><a href="System.Environment.html#c_GetEnvironmentVariable"><span class="hs-identifier hs-var">c_GetEnvironmentVariable</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#LPWSTR"><span class="hs-identifier hs-type">LPWSTR</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#LPWSTR"><span class="hs-identifier hs-type">LPWSTR</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-identifier">lookupEnv</span><span> </span><span class="hs-identifier">name</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-175"></span><span>    </span><span class="hs-identifier">withCString</span><span> </span><span class="hs-identifier">name</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-176"></span><span>      </span><span class="hs-identifier">litstring</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_getenv</span><span> </span><span class="hs-identifier">s</span><span>
</span><span id="line-177"></span><span>      </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">litstring</span><span> </span><span class="hs-operator">/=</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-178"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-identifier">enc</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getFileSystemEncoding</span><span>
</span><span id="line-179"></span><span>                </span><span class="hs-identifier">result</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">GHC.peekCString</span><span> </span><span class="hs-identifier">enc</span><span> </span><span class="hs-identifier">litstring</span><span>
</span><span id="line-180"></span><span>                </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">result</span><span>
</span><span id="line-181"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-182"></span><span>
</span><span id="line-183"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;getenv&quot;</span><span>
</span><span id="line-184"></span><span>   </span><span class="hs-identifier">c_getenv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CChar</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-187"></span><span id="local-6989586621679564367"><span class="annot"><a href="System.Environment.html#ioe_missingEnvVar"><span class="hs-identifier hs-type">ioe_missingEnvVar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564367"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-188"></span><span id="ioe_missingEnvVar"><span class="annot"><span class="annottext">ioe_missingEnvVar :: forall a. String -&gt; IO a
</span><a href="System.Environment.html#ioe_missingEnvVar"><span class="hs-identifier hs-var hs-var">ioe_missingEnvVar</span></a></span></span><span> </span><span id="local-6989586621679564172"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564172"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO a
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; String
-&gt; String
-&gt; Maybe CInt
-&gt; Maybe String
-&gt; IOError
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#NoSuchThing"><span class="hs-identifier hs-var">NoSuchThing</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;getEnv&quot;</span></span><span>
</span><span id="line-189"></span><span>    </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;no environment variable&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Maybe String
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564172"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-190"></span><span>
</span><span id="line-191"></span><span class="hs-comment">-- | @setEnv name value@ sets the specified environment variable to @value@.</span><span>
</span><span id="line-192"></span><span class="hs-comment">--</span><span>
</span><span id="line-193"></span><span class="hs-comment">-- Early versions of this function operated under the mistaken belief that</span><span>
</span><span id="line-194"></span><span class="hs-comment">-- setting an environment variable to the /empty string/ on Windows removes</span><span>
</span><span id="line-195"></span><span class="hs-comment">-- that environment variable from the environment.  For the sake of</span><span>
</span><span id="line-196"></span><span class="hs-comment">-- compatibility, it adopted that behavior on POSIX.  In particular</span><span>
</span><span id="line-197"></span><span class="hs-comment">--</span><span>
</span><span id="line-198"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-199"></span><span class="hs-comment">-- setEnv name \&quot;\&quot;</span><span>
</span><span id="line-200"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-201"></span><span class="hs-comment">--</span><span>
</span><span id="line-202"></span><span class="hs-comment">-- has the same effect as</span><span>
</span><span id="line-203"></span><span class="hs-comment">--</span><span>
</span><span id="line-204"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-205"></span><span class="hs-comment">-- `unsetEnv` name</span><span>
</span><span id="line-206"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-207"></span><span class="hs-comment">--</span><span>
</span><span id="line-208"></span><span class="hs-comment">-- If you'd like to be able to set environment variables to blank strings,</span><span>
</span><span id="line-209"></span><span class="hs-comment">-- use `System.Environment.Blank.setEnv`.</span><span>
</span><span id="line-210"></span><span class="hs-comment">--</span><span>
</span><span id="line-211"></span><span class="hs-comment">-- Throws `Control.Exception.IOException` if @name@ is the empty string or</span><span>
</span><span id="line-212"></span><span class="hs-comment">-- contains an equals sign.</span><span>
</span><span id="line-213"></span><span class="hs-comment">--</span><span>
</span><span id="line-214"></span><span class="hs-comment">-- @since 4.7.0.0</span><span>
</span><span id="line-215"></span><span class="annot"><a href="System.Environment.html#setEnv"><span class="hs-identifier hs-type">setEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-216"></span><span id="setEnv"><span class="annot"><span class="annottext">setEnv :: String -&gt; String -&gt; IO ()
</span><a href="System.Environment.html#setEnv"><span class="hs-identifier hs-var hs-var">setEnv</span></a></span></span><span> </span><span id="local-6989586621679564168"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564168"><span class="hs-identifier hs-var">key_</span></a></span></span><span> </span><span id="local-6989586621679564167"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564167"><span class="hs-identifier hs-var">value_</span></a></span></span><span>
</span><span id="line-217"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564165"><span class="hs-identifier hs-var">key</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO ()
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOErrorType -&gt; String -&gt; Maybe Handle -&gt; Maybe String -&gt; IOError
</span><a href="System.IO.Error.html#mkIOError"><span class="hs-identifier hs-var">mkIOError</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#InvalidArgument"><span class="hs-identifier hs-var">InvalidArgument</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;setEnv&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-218"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'='</span></span><span> </span><span class="annot"><span class="annottext">Char -&gt; String -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564165"><span class="hs-identifier hs-var">key</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO ()
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOErrorType -&gt; String -&gt; Maybe Handle -&gt; Maybe String -&gt; IOError
</span><a href="System.IO.Error.html#mkIOError"><span class="hs-identifier hs-var">mkIOError</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#InvalidArgument"><span class="hs-identifier hs-var">InvalidArgument</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;setEnv&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-219"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564162"><span class="hs-identifier hs-var">value</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="System.Environment.html#unsetEnv"><span class="hs-identifier hs-var">unsetEnv</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564165"><span class="hs-identifier hs-var">key</span></a></span><span>
</span><span id="line-220"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; IO ()
</span><a href="System.Environment.html#setEnv_"><span class="hs-identifier hs-var">setEnv_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564165"><span class="hs-identifier hs-var">key</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564162"><span class="hs-identifier hs-var">value</span></a></span><span>
</span><span id="line-221"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-222"></span><span>    </span><span id="local-6989586621679564165"><span class="annot"><span class="annottext">key :: String
</span><a href="#local-6989586621679564165"><span class="hs-identifier hs-var hs-var">key</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; String
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="GHC.List.html#takeWhile"><span class="hs-identifier hs-var">takeWhile</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\NUL'</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564168"><span class="hs-identifier hs-var">key_</span></a></span><span>
</span><span id="line-223"></span><span>    </span><span id="local-6989586621679564162"><span class="annot"><span class="annottext">value :: String
</span><a href="#local-6989586621679564162"><span class="hs-identifier hs-var hs-var">value</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; String
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="GHC.List.html#takeWhile"><span class="hs-identifier hs-var">takeWhile</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%2F%3D"><span class="hs-operator hs-var">/=</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\NUL'</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564167"><span class="hs-identifier hs-var">value_</span></a></span><span>
</span><span id="line-224"></span><span>
</span><span id="line-225"></span><span class="annot"><a href="System.Environment.html#setEnv_"><span class="hs-identifier hs-type">setEnv_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span id="setEnv_"><span class="annot"><span class="annottext">setEnv_ :: String -&gt; String -&gt; IO ()
</span><a href="System.Environment.html#setEnv_"><span class="hs-identifier hs-var hs-var">setEnv_</span></a></span></span><span> </span><span id="local-6989586621679564156"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564156"><span class="hs-identifier hs-var">key</span></a></span></span><span> </span><span id="local-6989586621679564155"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564155"><span class="hs-identifier hs-var">value</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; (Ptr CWchar -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564156"><span class="hs-identifier hs-var">key</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr CWchar -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679564154"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564154"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; (Ptr CWchar -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564155"><span class="hs-identifier hs-var">value</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr CWchar -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679564153"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564153"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-228"></span><span>  </span><span id="local-6989586621679564152"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679564152"><span class="hs-identifier hs-var">success</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; Ptr CWchar -&gt; IO Bool
</span><a href="System.Environment.html#c_SetEnvironmentVariable"><span class="hs-identifier hs-var">c_SetEnvironmentVariable</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564154"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564153"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-229"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679564152"><span class="hs-identifier hs-var">success</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; IO a
</span><a href="GHC.Windows.html#throwGetLastError"><span class="hs-identifier hs-var">throwGetLastError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;setEnv&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-230"></span><span>
</span><span id="line-231"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h SetEnvironmentVariableW&quot;</span><span>
</span><span id="line-232"></span><span>  </span><span id="c_SetEnvironmentVariable"><span class="annot"><a href="System.Environment.html#c_SetEnvironmentVariable"><span class="hs-identifier hs-var">c_SetEnvironmentVariable</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#LPTSTR"><span class="hs-identifier hs-type">LPTSTR</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#LPTSTR"><span class="hs-identifier hs-type">LPTSTR</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-cpp">
#else
</span><span>
</span><span id="line-235"></span><span class="hs-comment">-- NOTE: The 'setenv()' function is not available on all systems, hence we use</span><span>
</span><span id="line-236"></span><span class="hs-comment">-- 'putenv()'.  This leaks memory, but so do common implementations of</span><span>
</span><span id="line-237"></span><span class="hs-comment">-- 'setenv()' (AFAIK).</span><span>
</span><span id="line-238"></span><span class="hs-identifier">setEnv_</span><span> </span><span class="hs-identifier">k</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">putEnv</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">k</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-string">&quot;=&quot;</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">v</span><span class="hs-special">)</span><span>
</span><span id="line-239"></span><span>
</span><span id="line-240"></span><span class="hs-identifier">putEnv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-241"></span><span class="hs-identifier">putEnv</span><span> </span><span class="hs-identifier">keyvalue</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-242"></span><span>  </span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getFileSystemEncoding</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-special">(</span><span class="hs-special">`</span><span class="hs-identifier">GHC.newCString</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">keyvalue</span><span class="hs-special">)</span><span>
</span><span id="line-243"></span><span>  </span><span class="hs-comment">-- IMPORTANT: Do not free `s` after calling putenv!</span><span>
</span><span id="line-244"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-245"></span><span>  </span><span class="hs-comment">-- According to SUSv2, the string passed to putenv becomes part of the</span><span>
</span><span id="line-246"></span><span>  </span><span class="hs-comment">-- environment.</span><span>
</span><span id="line-247"></span><span>  </span><span class="hs-identifier">throwErrnoIf_</span><span> </span><span class="hs-special">(</span><span class="hs-operator">/=</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;putenv&quot;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">c_putenv</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span>
</span><span id="line-248"></span><span>
</span><span id="line-249"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;putenv&quot;</span><span> </span><span class="hs-identifier">c_putenv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CInt</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-252"></span><span class="hs-comment">-- | @unsetEnv name@ removes the specified environment variable from the</span><span>
</span><span id="line-253"></span><span class="hs-comment">-- environment of the current process.</span><span>
</span><span id="line-254"></span><span class="hs-comment">--</span><span>
</span><span id="line-255"></span><span class="hs-comment">-- Throws `Control.Exception.IOException` if @name@ is the empty string or</span><span>
</span><span id="line-256"></span><span class="hs-comment">-- contains an equals sign.</span><span>
</span><span id="line-257"></span><span class="hs-comment">--</span><span>
</span><span id="line-258"></span><span class="hs-comment">-- @since 4.7.0.0</span><span>
</span><span id="line-259"></span><span class="annot"><a href="System.Environment.html#unsetEnv"><span class="hs-identifier hs-type">unsetEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span id="unsetEnv"><span class="annot"><span class="annottext">unsetEnv :: String -&gt; IO ()
</span><a href="System.Environment.html#unsetEnv"><span class="hs-identifier hs-var hs-var">unsetEnv</span></a></span></span><span> </span><span id="local-6989586621679564148"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564148"><span class="hs-identifier hs-var">key</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; (Ptr CWchar -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564148"><span class="hs-identifier hs-var">key</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr CWchar -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679564147"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564147"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-262"></span><span>  </span><span id="local-6989586621679564146"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679564146"><span class="hs-identifier hs-var">success</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; Ptr CWchar -&gt; IO Bool
</span><a href="System.Environment.html#c_SetEnvironmentVariable"><span class="hs-identifier hs-var">c_SetEnvironmentVariable</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564147"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
forall a. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span>
</span><span id="line-263"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679564146"><span class="hs-identifier hs-var">success</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-264"></span><span>    </span><span class="hs-comment">-- We consider unsetting an environment variable that does not exist not as</span><span>
</span><span id="line-265"></span><span>    </span><span class="hs-comment">-- an error, hence we ignore eRROR_ENVVAR_NOT_FOUND.</span><span>
</span><span id="line-266"></span><span>    </span><span id="local-6989586621679564144"><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564144"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO DWORD
</span><a href="System.Environment.html#c_GetLastError"><span class="hs-identifier hs-var">c_GetLastError</span></a></span><span>
</span><span id="line-267"></span><span>    </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DWORD
</span><a href="#local-6989586621679564144"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD -&gt; DWORD -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">DWORD
</span><a href="System.Environment.html#eRROR_ENVVAR_NOT_FOUND"><span class="hs-identifier hs-var">eRROR_ENVVAR_NOT_FOUND</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-268"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; IO a
</span><a href="GHC.Windows.html#throwGetLastError"><span class="hs-identifier hs-var">throwGetLastError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;unsetEnv&quot;</span></span><span class="hs-cpp">
#else
</span><span class="hs-cpp">
#if defined(HAVE_UNSETENV)
</span><span class="hs-identifier">unsetEnv</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withFilePath</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">throwErrnoIf_</span><span> </span><span class="hs-special">(</span><span class="hs-operator">/=</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;unsetEnv&quot;</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">c_unsetenv</span><span class="hs-special">)</span><span>
</span><span id="line-273"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;__hsbase_unsetenv&quot;</span><span> </span><span class="hs-identifier">c_unsetenv</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CInt</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">unsetEnv</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">setEnv_</span><span> </span><span class="hs-identifier">key</span><span> </span><span class="hs-string">&quot;&quot;</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-280"></span><span class="hs-comment">{-|
'withArgs' @args act@ - while executing action @act@, have 'getArgs'
return @args@.
-}</span><span>
</span><span id="line-284"></span><span id="local-6989586621679564346"><span class="annot"><a href="System.Environment.html#withArgs"><span class="hs-identifier hs-type">withArgs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564346"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564346"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-285"></span><span id="withArgs"><span class="annot"><span class="annottext">withArgs :: forall a. [String] -&gt; IO a -&gt; IO a
</span><a href="System.Environment.html#withArgs"><span class="hs-identifier hs-var hs-var">withArgs</span></a></span></span><span> </span><span id="local-6989586621679564142"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564142"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span id="local-6989586621679564141"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679564141"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-286"></span><span>   </span><span id="local-6989586621679564140"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564140"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO String
</span><a href="System.Environment.html#getProgName"><span class="hs-identifier hs-var">System.Environment.getProgName</span></a></span><span>
</span><span id="line-287"></span><span>   </span><span class="annot"><span class="annottext">[String] -&gt; IO a -&gt; IO a
forall a. [String] -&gt; IO a -&gt; IO a
</span><a href="System.Environment.html#withArgv"><span class="hs-identifier hs-var">withArgv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564140"><span class="hs-identifier hs-var">p</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564142"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679564141"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-288"></span><span>
</span><span id="line-289"></span><span class="hs-comment">{-|
'withProgName' @name act@ - while executing action @act@,
have 'getProgName' return @name@.
-}</span><span>
</span><span id="line-293"></span><span id="local-6989586621679564344"><span class="annot"><a href="System.Environment.html#withProgName"><span class="hs-identifier hs-type">withProgName</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564344"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564344"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-294"></span><span id="withProgName"><span class="annot"><span class="annottext">withProgName :: forall a. String -&gt; IO a -&gt; IO a
</span><a href="System.Environment.html#withProgName"><span class="hs-identifier hs-var hs-var">withProgName</span></a></span></span><span> </span><span id="local-6989586621679564137"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564137"><span class="hs-identifier hs-var">nm</span></a></span></span><span> </span><span id="local-6989586621679564136"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679564136"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-295"></span><span>   </span><span id="local-6989586621679564135"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564135"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO [String]
</span><a href="System.Environment.html#getArgs"><span class="hs-identifier hs-var">System.Environment.getArgs</span></a></span><span>
</span><span id="line-296"></span><span>   </span><span class="annot"><span class="annottext">[String] -&gt; IO a -&gt; IO a
forall a. [String] -&gt; IO a -&gt; IO a
</span><a href="System.Environment.html#withArgv"><span class="hs-identifier hs-var">withArgv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564137"><span class="hs-identifier hs-var">nm</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564135"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679564136"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-297"></span><span>
</span><span id="line-298"></span><span class="hs-comment">-- Worker routine which marshals and replaces an argv vector for</span><span>
</span><span id="line-299"></span><span class="hs-comment">-- the duration of an action.</span><span>
</span><span id="line-300"></span><span>
</span><span id="line-301"></span><span id="local-6989586621679564134"><span class="annot"><a href="System.Environment.html#withArgv"><span class="hs-identifier hs-type">withArgv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564134"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564134"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-302"></span><span id="withArgv"><span class="annot"><span class="annottext">withArgv :: forall a. [String] -&gt; IO a -&gt; IO a
</span><a href="System.Environment.html#withArgv"><span class="hs-identifier hs-var hs-var">withArgv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[String] -&gt; IO a -&gt; IO a
forall a. [String] -&gt; IO a -&gt; IO a
</span><a href="System.Environment.html#withProgArgv"><span class="hs-identifier hs-var">withProgArgv</span></a></span><span>
</span><span id="line-303"></span><span>
</span><span id="line-304"></span><span id="local-6989586621679564132"><span class="annot"><a href="System.Environment.html#withProgArgv"><span class="hs-identifier hs-type">withProgArgv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564132"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679564132"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-305"></span><span id="withProgArgv"><span class="annot"><span class="annottext">withProgArgv :: forall a. [String] -&gt; IO a -&gt; IO a
</span><a href="System.Environment.html#withProgArgv"><span class="hs-identifier hs-var hs-var">withProgArgv</span></a></span></span><span> </span><span id="local-6989586621679564129"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564129"><span class="hs-identifier hs-var">new_args</span></a></span></span><span> </span><span id="local-6989586621679564128"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679564128"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-306"></span><span>  </span><span id="local-6989586621679564127"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564127"><span class="hs-identifier hs-var">pName</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO String
</span><a href="System.Environment.html#getProgName"><span class="hs-identifier hs-var">System.Environment.getProgName</span></a></span><span>
</span><span id="line-307"></span><span>  </span><span id="local-6989586621679564126"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564126"><span class="hs-identifier hs-var">existing_args</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO [String]
</span><a href="System.Environment.html#getArgs"><span class="hs-identifier hs-var">System.Environment.getArgs</span></a></span><span>
</span><span id="line-308"></span><span>  </span><span class="annot"><span class="annottext">IO () -&gt; IO () -&gt; IO a -&gt; IO a
forall a b c. IO a -&gt; IO b -&gt; IO c -&gt; IO c
</span><a href="Control.Exception.Base.html#bracket_"><span class="hs-identifier hs-var">bracket_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[String] -&gt; IO ()
</span><a href="System.Environment.html#setProgArgv"><span class="hs-identifier hs-var">setProgArgv</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564129"><span class="hs-identifier hs-var">new_args</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-309"></span><span>           </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[String] -&gt; IO ()
</span><a href="System.Environment.html#setProgArgv"><span class="hs-identifier hs-var">setProgArgv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564127"><span class="hs-identifier hs-var">pName</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564126"><span class="hs-identifier hs-var">existing_args</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-310"></span><span>           </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679564128"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-311"></span><span>
</span><span id="line-312"></span><span class="annot"><a href="System.Environment.html#setProgArgv"><span class="hs-identifier hs-type">setProgArgv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-313"></span><span id="setProgArgv"><span class="annot"><span class="annottext">setProgArgv :: [String] -&gt; IO ()
</span><a href="System.Environment.html#setProgArgv"><span class="hs-identifier hs-var hs-var">setProgArgv</span></a></span></span><span> </span><span id="local-6989586621679564124"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564124"><span class="hs-identifier hs-var">argv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-314"></span><span>  </span><span id="local-6989586621679564123"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679564123"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#argvEncoding"><span class="hs-identifier hs-var">argvEncoding</span></a></span><span>
</span><span id="line-315"></span><span>  </span><span class="annot"><span class="annottext">TextEncoding
-&gt; [String] -&gt; (Int -&gt; Ptr (Ptr CChar) -&gt; IO ()) -&gt; IO ()
forall a.
TextEncoding
-&gt; [String] -&gt; (Int -&gt; Ptr (Ptr CChar) -&gt; IO a) -&gt; IO a
</span><a href="GHC.Foreign.html#withCStringsLen"><span class="hs-identifier hs-var">GHC.withCStringsLen</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679564123"><span class="hs-identifier hs-var">enc</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679564124"><span class="hs-identifier hs-var">argv</span></a></span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr (Ptr CChar) -&gt; IO ()) -&gt; IO ())
-&gt; (Int -&gt; Ptr (Ptr CChar) -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679564121"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679564121"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span id="local-6989586621679564120"><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564120"><span class="hs-identifier hs-var">css</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-316"></span><span>    </span><span class="annot"><span class="annottext">CInt -&gt; Ptr (Ptr CChar) -&gt; IO ()
</span><a href="System.Environment.html#c_setProgArgv"><span class="hs-identifier hs-var">c_setProgArgv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679564121"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr CChar)
</span><a href="#local-6989586621679564120"><span class="hs-identifier hs-var">css</span></a></span><span>
</span><span id="line-317"></span><span>
</span><span id="line-318"></span><span class="hs-comment">-- setProgArgv copies the arguments</span><span>
</span><span id="line-319"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;setProgArgv&quot;</span></span><span>
</span><span id="line-320"></span><span>  </span><span id="c_setProgArgv"><span class="annot"><a href="System.Environment.html#c_setProgArgv"><span class="hs-identifier hs-var">c_setProgArgv</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CString"><span class="hs-identifier hs-type">CString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-321"></span><span>
</span><span id="line-322"></span><span class="hs-comment">-- |'getEnvironment' retrieves the entire environment as a</span><span>
</span><span id="line-323"></span><span class="hs-comment">-- list of @(key,value)@ pairs.</span><span>
</span><span id="line-324"></span><span class="hs-comment">--</span><span>
</span><span id="line-325"></span><span class="hs-comment">-- If an environment entry does not contain an @\'=\'@ character,</span><span>
</span><span id="line-326"></span><span class="hs-comment">-- the @key@ is the whole entry and the @value@ is the empty string.</span><span>
</span><span id="line-327"></span><span class="annot"><a href="System.Environment.html#getEnvironment"><span class="hs-identifier hs-type">getEnvironment</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-cpp">

#if defined(mingw32_HOST_OS)
</span><span id="getEnvironment"><span class="annot"><span class="annottext">getEnvironment :: IO [(String, String)]
</span><a href="System.Environment.html#getEnvironment"><span class="hs-identifier hs-var hs-var">getEnvironment</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (Ptr CWchar)
-&gt; (Ptr CWchar -&gt; IO Bool)
-&gt; (Ptr CWchar -&gt; IO [(String, String)])
-&gt; IO [(String, String)]
forall a b c. IO a -&gt; (a -&gt; IO b) -&gt; (a -&gt; IO c) -&gt; IO c
</span><a href="Control.Exception.Base.html#bracket"><span class="hs-identifier hs-var">bracket</span></a></span><span> </span><span class="annot"><span class="annottext">IO (Ptr CWchar)
</span><a href="System.Environment.html#c_GetEnvironmentStrings"><span class="hs-identifier hs-var">c_GetEnvironmentStrings</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO Bool
</span><a href="System.Environment.html#c_FreeEnvironmentStrings"><span class="hs-identifier hs-var">c_FreeEnvironmentStrings</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO [(String, String)]) -&gt; IO [(String, String)])
-&gt; (Ptr CWchar -&gt; IO [(String, String)]) -&gt; IO [(String, String)]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679564116"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564116"><span class="hs-identifier hs-var">pBlock</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-331"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564116"><span class="hs-identifier hs-var">pBlock</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; Ptr CWchar -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
forall a. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">[(String, String)] -&gt; IO [(String, String)]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-332"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO [(String, String)]
</span><a href="#local-6989586621679564115"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564116"><span class="hs-identifier hs-var">pBlock</span></a></span><span>
</span><span id="line-333"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-334"></span><span>    </span><span id="local-6989586621679564115"><span class="annot"><span class="annottext">go :: Ptr CWchar -&gt; IO [(String, String)]
</span><a href="#local-6989586621679564115"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679564103"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564103"><span class="hs-identifier hs-var">pBlock</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-335"></span><span>        </span><span class="hs-comment">-- The block is terminated by a null byte where there</span><span>
</span><span id="line-336"></span><span>        </span><span class="hs-comment">-- should be an environment variable of the form X=Y</span><span>
</span><span id="line-337"></span><span>        </span><span id="local-6989586621679564102"><span class="annot"><span class="annottext">CWchar
</span><a href="#local-6989586621679564102"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO CWchar
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564103"><span class="hs-identifier hs-var">pBlock</span></a></span><span>
</span><span id="line-338"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">CWchar
</span><a href="#local-6989586621679564102"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar -&gt; CWchar -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar
</span><span class="hs-number">0</span></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">[(String, String)] -&gt; IO [(String, String)]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-339"></span><span>         </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-340"></span><span>          </span><span class="hs-comment">-- Seek the next pair (or terminating null):</span><span>
</span><span id="line-341"></span><span>          </span><span id="local-6989586621679564101"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564101"><span class="hs-identifier hs-var">pBlock'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; Bool -&gt; IO (Ptr CWchar)
forall {b} {b}. Ptr b -&gt; Bool -&gt; IO (Ptr b)
</span><a href="#local-6989586621679564100"><span class="hs-identifier hs-var">seekNull</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564103"><span class="hs-identifier hs-var">pBlock</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-342"></span><span>          </span><span class="hs-comment">-- We now know the length in bytes, but ignore it when</span><span>
</span><span id="line-343"></span><span>          </span><span class="hs-comment">-- getting the actual String:</span><span>
</span><span id="line-344"></span><span>          </span><span id="local-6989586621679564099"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564099"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO String
</span><a href="Foreign.C.String.html#peekCWString"><span class="hs-identifier hs-var">peekCWString</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564103"><span class="hs-identifier hs-var">pBlock</span></a></span><span>
</span><span id="line-345"></span><span>          </span><span class="annot"><span class="annottext">([(String, String)] -&gt; [(String, String)])
-&gt; IO [(String, String)] -&gt; IO [(String, String)]
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; (String, String)
</span><a href="System.Environment.html#divvy"><span class="hs-identifier hs-var">divvy</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564099"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">(String, String) -&gt; [(String, String)] -&gt; [(String, String)]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO [(String, String)] -&gt; IO [(String, String)])
-&gt; IO [(String, String)] -&gt; IO [(String, String)]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO [(String, String)]
</span><a href="#local-6989586621679564115"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679564101"><span class="hs-identifier hs-var">pBlock'</span></a></span><span>
</span><span id="line-346"></span><span>
</span><span id="line-347"></span><span>    </span><span class="hs-comment">-- Returns pointer to the byte *after* the next null</span><span>
</span><span id="line-348"></span><span>    </span><span id="local-6989586621679564100"><span class="annot"><span class="annottext">seekNull :: Ptr b -&gt; Bool -&gt; IO (Ptr b)
</span><a href="#local-6989586621679564100"><span class="hs-identifier hs-var hs-var">seekNull</span></a></span></span><span> </span><span id="local-6989586621679564089"><span class="annot"><span class="annottext">Ptr b
</span><a href="#local-6989586621679564089"><span class="hs-identifier hs-var">pBlock</span></a></span></span><span> </span><span id="local-6989586621679564088"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679564088"><span class="hs-identifier hs-var">done</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-349"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679564084"><span class="annot"><span class="annottext">pBlock' :: Ptr b
</span><a href="#local-6989586621679564084"><span class="hs-identifier hs-var hs-var">pBlock'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr b
</span><a href="#local-6989586621679564089"><span class="hs-identifier hs-var">pBlock</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr b -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CWchar
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-350"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679564088"><span class="hs-identifier hs-var">done</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Ptr b -&gt; IO (Ptr b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr b
forall a. Ptr a
</span><a href="#local-6989586621679564084"><span class="hs-identifier hs-var">pBlock'</span></a></span><span>
</span><span id="line-351"></span><span>         </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-352"></span><span>           </span><span id="local-6989586621679564080"><span class="annot"><span class="annottext">Word8
</span><a href="#local-6989586621679564080"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO Word8
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall a. Ptr a
</span><a href="#local-6989586621679564084"><span class="hs-identifier hs-var">pBlock'</span></a></span><span>
</span><span id="line-353"></span><span>           </span><span class="annot"><span class="annottext">Ptr b -&gt; Bool -&gt; IO (Ptr b)
</span><a href="#local-6989586621679564100"><span class="hs-identifier hs-var">seekNull</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr b
forall a. Ptr a
</span><a href="#local-6989586621679564084"><span class="hs-identifier hs-var">pBlock'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word8
</span><a href="#local-6989586621679564080"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Word8 -&gt; Word8 -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word8
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-354"></span><span>
</span><span id="line-355"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h GetEnvironmentStringsW&quot;</span><span>
</span><span id="line-356"></span><span>  </span><span id="c_GetEnvironmentStrings"><span class="annot"><a href="System.Environment.html#c_GetEnvironmentStrings"><span class="hs-identifier hs-var">c_GetEnvironmentStrings</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-357"></span><span>
</span><span id="line-358"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h FreeEnvironmentStringsW&quot;</span><span>
</span><span id="line-359"></span><span>  </span><span id="c_FreeEnvironmentStrings"><span class="annot"><a href="System.Environment.html#c_FreeEnvironmentStrings"><span class="hs-identifier hs-var">c_FreeEnvironmentStrings</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-cpp">
#else
</span><span class="hs-identifier">getEnvironment</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-362"></span><span>   </span><span class="hs-identifier">pBlock</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getEnvBlock</span><span>
</span><span id="line-363"></span><span>   </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">pBlock</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-364"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-365"></span><span>      </span><span class="hs-identifier">enc</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getFileSystemEncoding</span><span>
</span><span id="line-366"></span><span>      </span><span class="hs-identifier">stuff</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekArray0</span><span> </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-identifier">pBlock</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">mapM</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">GHC.peekCString</span><span> </span><span class="hs-identifier">enc</span><span class="hs-special">)</span><span>
</span><span id="line-367"></span><span>      </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">map</span><span> </span><span class="hs-identifier">divvy</span><span> </span><span class="hs-identifier">stuff</span><span class="hs-special">)</span><span>
</span><span id="line-368"></span><span>
</span><span id="line-369"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;__hscore_environ&quot;</span><span>
</span><span id="line-370"></span><span>  </span><span class="hs-identifier">getEnvBlock</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CString</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-373"></span><span class="annot"><a href="System.Environment.html#divvy"><span class="hs-identifier hs-type">divvy</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-374"></span><span id="divvy"><span class="annot"><span class="annottext">divvy :: String -&gt; (String, String)
</span><a href="System.Environment.html#divvy"><span class="hs-identifier hs-var hs-var">divvy</span></a></span></span><span> </span><span id="local-6989586621679564079"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564079"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-375"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; (String, String)
forall a. (a -&gt; Bool) -&gt; [a] -&gt; ([a], [a])
</span><a href="GHC.List.html#break"><span class="hs-identifier hs-var">break</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'='</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564079"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-376"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679564077"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564077"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564077"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- don't barf (like Posix.getEnvironment)</span><span>
</span><span id="line-377"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679564076"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564076"><span class="hs-identifier hs-var">name</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Char
</span><span class="hs-identifier">_</span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679564075"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564075"><span class="hs-identifier hs-var">value</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564076"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679564075"><span class="hs-identifier hs-var">value</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-378"></span></pre></body></html>